package cn.com.callback


import cn.com.elite.EliteBean;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.Util;
import net.sf.json.JSONObject

/**
 * 
 * @author Rick
 * @use 获取用户信息，写入本地
 *
 *
 */
public class RICKTEST implements ServiceBackInvoke{
	private static final Log log=LogFactory.getLog(RICKTEST.class);
	private String charset = "utf-8"; //设置字符集
	private int timeout = 100000; //设置请求超时时间
	private int enableSSLflag = 1;
	public String doCallBack(EliteBean eliteBean, HttpServletRequest request,HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json");
		JSONObject result = new JSONObject();
		def smap,oJson,SaveResult;
		try {
			//获取客户端传参
			def r_custname = Util.filterForObject(request.getParameter("customername")); //获取客户姓名

			//传参处理
			Map<String, String> map = new HashMap<String, String>();
			map.put("customername", r_custname);
			map.put("key", "ca3c64a49d1f11ecbed6d703198897725e7aba55");
			map.put("austomername", r_custname);
			def	ASCIIMD5 = ASCIIORDER(map);
			log.debug("ASCIIMD5:"+ASCIIMD5);
			//列表接口调用



		}catch (Exception e) {
			log.error("errormsg:", e)
			result.put("code", "-1");
			result.put("msg", "调用失败！");
			return result;
		}
	}


/**
 * 
 * @use 客户列表接口调用
 * @param eliteBean
 * @param Custname,Mobile,Idno,Custnameid
 * @return
 */




	public String ASCIIORDER(Map<String, String> map) {

		// 对所有传入参数按照字段名的 ASCII 码从小到大排序（字典序）
		List<Map.Entry<String, String>> infoIds = new ArrayList<Map.Entry<String, String>>(map.entrySet());
		Collections.sort(infoIds, new Comparator<Map.Entry<String, String>>() {
			public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
				return (o1.getKey()).toString().compareTo(o2.getKey());
			}
		});

		// 构造签名键值对的格式
		StringBuilder sb = new StringBuilder();
		for (Map.Entry<String, String> item : infoIds) {
			if (item.getKey() != null || item.getKey() != "") {
				String key = item.getKey();
				String val = item.getValue();
				if (!(val == "" || val == null)) {
					sb.append(key + "=" + val + "&");
				}
			}
		}
		log.debug("ASCIIMD5:"+sb.toString());
		//charset=UTF-8&sign_type=RSA_1_256&status=0&version=2.0&
		return  sb.toString();

	}


}








